/**
 * Copyright (C), 2015-2019, 鼎一致远科技发展有限公司
 * FileName: Test
 * Author:   Vince-ZZ
 * Date:     2019/4/10 0010 下午 8:36
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.study.one;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static<T> List<T> filter(List<T> list,Prediacate<T> p){
        List<T> result = new ArrayList<T>();
        for (T item: list) {
            if(p.test(item)){
                result.add(item);
            }
        }
        return result;
    };
    public static<T> void init(List<Apple> list){
        list.add(new Apple("green",180));
        list.add(new Apple("green",150));
        list.add(new Apple("green",140));
        list.add(new Apple("yellow",180));
        list.add(new Apple("yellow",150));
        list.add(new Apple("yellow",140));
        list.add(new Apple("blue",180));
        list.add(new Apple("blue",150));
        list.add(new Apple("blue",140));
        list.add(new Apple("red",180));
        list.add(new Apple("red",150));
        list.add(new Apple("red",140));
        list.add(new Apple("black",180));
        list.add(new Apple("black",150));
        list.add(new Apple("black",140));

    };
    public static void main(String[] args) {
        List<Apple> list = new ArrayList<>();
        init(list);
        //使用lambda过滤出苹果颜色为"green"的苹果集合
        List<Apple> greenAppleList = filter(list,(Apple apple)->apple.getColor().equals("green"));
        //使用lambda过滤出苹果颜色为"yellow"的苹果集合
        List<Apple> yellowAppleList = filter(list,(Apple apple)->apple.getColor().equals("yellow"));
        //使用lambda过滤出苹果颜色为"red"的苹果集合
        List<Apple> redAppleList = filter(list,(Apple apple)->apple.getColor().equals("red"));
        System.out.println(yellowAppleList);
    }
}
